<template>
    <header>
        <!--上半部分-->
        <div class="container">
            <div class="site-top-bar">
                <div class="top-bar-nav">
                    <a href="javascript:void(0);">小米商城</a><span class="sep">|</span>
                    <a href="javascript:void(0);">MIUI</a><span class="sep">|</span>
                    <a href="javascript:void(0);">IoT</a><span class="sep">|</span>
                    <a href="javascript:void(0);">云服务</a><span class="sep">|</span>
                    <a href="javascript:void(0);">金融</a><span class="sep">|</span>
                    <a href="javascript:void(0);">有品</a><span class="sep">|</span>
                    <a href="javascript:void(0);">小爱开放平台</a><span class="sep">|</span>
                    <a href="javascript:void(0);">企业团购</a><span class="sep">|</span>
                    <a href="javascript:void(0);">资质证照</a><span class="sep">|</span>
                    <a href="javascript:void(0);">协议规则</a><span class="sep">|</span>
                    <a href="javascript:void(0);">下载app</a><span class="sep">|</span>
                    <a href="javascript:void(0);">Select Location</a>
                </div>
                <div class="bop-bar-car">
                    <a href="javascript:void (0);">
                        <span class="iconfont-cart1"></span>购物车<span>（0）</span>
                    </a>
                </div>
                <div class="top-bar-info">
                    <router-link v-if="!userName" to="/login" class="link" >登录</router-link>
                    <router-link v-else to="/login" class="link" >{{userName}}</router-link><span class="sep">|</span>
                    <router-link to="/order" class="link" >我的订单</router-link><span class="sep">|</span>
                    <span class="message">消息通知</span>
                </div>
                <!--清除浮动-->
                <div class="clear"></div>
            </div>
        </div>
        <!--下半部分-->
        <div class="site-header">
            <div class="site-header-container">
                <!--Logo-->
                <div class="header-logo">
                    <a href="javascript:void(0);"></a>
                </div>
                <!--导航栏-->
                <div class="header-nav">
                    <ul class="nav-list">
                        <li class="nav-item">
                            <a href="javascript:void (0);">小米手机</a>

                            <!-- 推荐商品 -->
                            <div class="J_navMenu">
                                <ul class="children-list">
                                    <li>
                                        <router-link :to="{path:'product',params: {id:item.id}}" :key="item.id" v-for="item in commodityList">
                                            <div class="figure">
                                                <img :src="item.mainImage" alt="">
                                            </div>
                                            <div class="title">
                                                {{item.name}}
                                            </div>
                                            <div class="price">
                                                {{item.price}}元
                                            </div>
                                         </router-link>
                                    </li>
                                </ul>
                            </div>
                        </li>
                        <li class="nav-item"><a href="javascript:void (0);">Redmi 红米</a></li>
                        <li class="nav-item"><a href="javascript:void (0);">电视</a></li>
                        <li class="nav-item"><a href="javascript:void (0);">笔记本</a></li>
                        <li class="nav-item"><a href="javascript:void (0);">家电</a></li>
                        <li class="nav-item"><a href="javascript:void (0);">路由器</a></li>
                        <li class="nav-item"><a href="javascript:void (0);">智能硬件</a></li>
                        <li class="nav-item"><a href="javascript:void (0);">服务</a></li>
                        <li class="nav-item"><a href="javascript:void (0);">社区</a></li>
                    </ul>
                </div>
                <!--搜索框-->
                <div class="header-search">
                    <input type="text" class="search-text"/>
                    <button class="search-btn iconfont iconseach"></button>
                </div>
            </div>
        </div>
    </header>
</template>

<script>
    export default {
        name: "NavHeader",
        data() {
            return {
                userName:"Break",
                commodityList: []
            }
        },
        mounted() {
            this.getProductList();
        },
        methods: {
            getProductList() {
                this.axios.get('/products', {
                    params: {
                        categoryId: '100012',
                        pageSize: 6
                    }
                }).then(e => {
                    // console.log(e.data.data.list);
                    this.commodityList = e.data.data.list;
                })
            }
        }
    }
</script>

<style scoped lang="scss">
    @import "../../resource/scss/mixin";
    @import "../../resource/scss/config";

    header {
        .container {
            height: 40px;
            background-color: #333;
        }

        .site-top-bar {
            width: 1226px;
            margin-left: auto;
            margin-right: auto;
            /*左边导航栏*/
            .top-bar-nav {
                height: 100%;
                float: left;

                a {
                    &:hover {
                        color: #fff;
                    }

                    display: inline-block;
                    line-height: 40px;
                    color: #b0b0b0;
                }
            }

            .sep {
                margin: 0 .3rem;
                color: #424242;
                font-family: sans-serif;
            }

            /*右边购物车*/
            .bop-bar-car {
                float: right;
                margin-left: 15px;

                a {
                    display: block;
                    width: 120px;
                    height: 40px;
                    line-height: 40px;
                    background-color: #424242;
                    text-align: center;
                    color: #b0b0b0;

                    .iconfont-cart1 {
                        vertical-align: -5px;
                        @include bgImg(20px, 20px, '../../public/imgs/icon-cart.png');
                        margin-right: 4px;
                    }

                    span {
                        display: inline-block;
                    }
                }
            }

            /*用户功能导航栏*/
            .top-bar-info {
                float: right;
                height: 40px;

                .link {
                    &:hover {
                        color: #fff;
                    }

                    line-height: 40px;
                    color: #b0b0b0;
                    padding: 0 5px;
                    text-align: center;
                }

                .message {
                    color: #b0b0b0;
                }
            }

            .clear {
                clear: both;
            }
        }

        .site-header {
            position: relative;

            /*下半部分*/
            .site-header-container {
                /*position: relative;*/
                width: 1226px;
                height: 100px;
                margin: 0 auto;
                @include flex();
                /*logo部分*/
                .header-logo {
                    width: 62px;
                    height: 62px;
                    background-color: #ff6700;
                    cursor: pointer;
                    overflow: hidden;

                    a {
                        display: block;
                        width: 124px;
                        height: 62px;
                        transition: margin-left .3s;

                        &:before {
                            @include bgImg(62px, 62px, "../../public/imgs/logo-mi.png", 62px, 62px);
                        }

                        &:after {
                            @include bgImg(62px, 62px, "../../public/imgs/mi-home.png", 62px, 62px);
                        }

                        &:before, &:after {
                            content: ' ';
                            display: inline-block;
                            float: left;
                        }

                        &:hover {
                            margin-left: -62px;
                        }
                    }
                }

                /*导航部分*/
                .header-nav {
                    /*position: relative;*/
                    height: 88px;
                    width: 850px;
                    /*导航栏*/
                    .nav-list {
                        .nav-item {
                            float: left;
                            line-height: 88px;
                            padding: 0 10px;
                            font-size: 16px;
                            cursor: pointer;

                            &:hover .J_navMenu {
                                opacity: 1;
                                height: 229px;
                                transition: all .3s;
                            }

                            &:hover a {
                                color: #ff6700;
                            }

                            a {
                                color: #333;
                                transition: color .3s;
                            }

                        }
                    }
                }

                /*搜索框*/
                .header-search {
                    width: 296px;
                    height: 50px;

                    .search-text {
                        display: inline-block;
                        vertical-align: middle;
                        border: 1px solid #e0e0e0;
                        border-right: 0;
                        width: 223px;
                        height: 48px;
                        box-sizing: border-box;
                        padding: 0 10px;
                        font-size: 14px;
                        color: #333;
                        transition: border .3s;

                        &:focus,
                        &:focus .search-btn {
                            border-color: #ff6700 !important;
                        }
                    }

                    &:hover .search-text,
                    &:hover .search-btn {
                        border-color: #B0B0B0;
                    }

                    .search-btn {
                        display: inline-block;
                        vertical-align: middle;
                        border: 1px solid #e0e0e0;
                        height: 48px;
                        width: 48px;
                        color: #616161;
                        font-size: 24px;
                        background-color: #fff;
                        cursor: pointer;
                        transition: all .3s;

                        &:hover {
                            background-color: #ff6700;
                            color: #fff;
                            border-color: #ff6700;
                        }
                    }

                    .border-ff6700 {
                        border-color: #ff6700 !important;
                    }
                }
            }
        }

        /*推荐商品*/
        .J_navMenu {
            position: absolute;
            left: 0;
            top: 88px;
            height: 0;
            opacity: 0;
            width: 100%;
            z-index: 12;
            overflow: hidden;
            box-shadow: 0 3px 4px rgba(0, 0, 0, .18);

            .children-list {
                width: $min-width;
                height: 100%;
                margin: 0 auto;
                background: #fff;
                overflow: hidden;
                a {
                    position: relative;
                    display: block;
                    width: 16.6%;
                    height: 220px;
                    float: left;
                    font-size: 12px;
                    text-align: center;

                    img {
                        width: auto;
                        height: 111px;
                        margin-top: 26px;
                    }

                    .figure {
                        height: 137px;
                    }

                    .title {
                        color: $colorB;
                        font-weight: bold;
                        margin-top: 19px;
                        margin-bottom: 8px;
                        line-height: 20px;
                    }

                    .price {
                        color: $colorA;
                        line-height: 20px;
                    }

                    &:before {
                        content: "";
                        position: absolute;
                        top: 28px;
                        right: 0;
                        height: 100px;
                        width: 1px;
                        background-color: $colorF;
                    }

                    &:last-child:before {
                        display: none;
                    }
                }
            }
        }

        .J_navMenu_show {
            height: 229px;
            opacity: 1;
        }
    }
</style>